<template>
  <van-pull-refresh
    v-model="isLoading"
    @refresh="onRefresh"
    class="refresh-main"
  >
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
      v-if="nolist"
    >
      <order-item
        v-for="(item,index) in list"
        :key="index"
        :head-img="item.image"
        :user-name="item.name"
        :price="item.je"
        :amount="item.jf"
        :mark="item.remark"
        :status="item.status"
        :type-show="[2,3].includes(activeInx)"
        :type="item.type"
        :to="`/order/orderDetail?id=${item.id}&status=${item.status}&act=${activeInx}`"
      ></order-item>
    </van-list>
    <nolist
      imgshow="order"
      v-else
    ></nolist>
  </van-pull-refresh>
</template>

<script type="text/ecmascript-6">
import { trads } from "@/api";
import orderItem from "@/components/common/orderItem";
import nolist from "@/components/common/nolist";
export default {
  //接收父级传递的参数
  props: ['activeInx'],
  //监听数据变化
  watch: {},
  data() {
    return {
       list: [],
      loading: true,
      finished: false,
      isLoading: false,
      page: 1,
      nolist: true,
      clicked: false
    };
  },
  //实例初始化之前触发事件
  beforeCreate() {},
  //实例化之后触发事件
  created() {},
  //实时监控data参数数据变化
  computed: {},
  //模板组件
  components: {
    nolist,
    orderItem
  },
  //执行方法
  methods: {
        onLoad() {
      this.page += 1;
      this.clicked = false;
      this.getList();
    },
    onRefresh() {
      this.nolist = true;
      this.clicked = true;
     
      setTimeout(() => {
        this.$toast("刷新成功");
        this.isLoading = false;
        this.getList();
         this.loading=true
      }, 500);
      this.page = 1;
      this.list = [];
       this.loading=false
    },
    getList() {
      trads.order({ type: this.activeInx + 1, page: this.page }).then(res => {
        if (res.code == 1000) {
          if (Number(res.count) != 0 && res.result.length != 0) {
            if (this.clicked) {
              this.list = [...res.result];
            } else {
              this.list = [...this.list, ...res.result];
            }

            this.loading = false;
            this.nolist = true;
            if (this.list.length == Number(res.count)) {
              this.finished = true;
            }
          } else {
            this.list = [];
            this.nolist = false;
            this.loading = false;
            this.finished = true;
          }
        }
      });
    }
  },
  mounted() {
     this.getList();
  }
  //路由退出时候调用
  //beforeRouteLeave(to, from, next){next()}
};
</script>

<style scoped lang="less">
</style>
